package com.his.registration.mapper;

import com.his.dto.CheckCharge;
import com.his.dto.CheckResult;
import com.his.registration.pojo.CheckRequest;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @BelongsProject: workspace-idea
 * @BelongsPackage: com.his.registration.mapper
 * @Author: ZhangYing
 * @Date: 2023/7/2 15:44
 * @Description:
 */
@Mapper
public interface CheckRequestMapper {
    //查询患者所有的检查费用
    @Select("select c.id,m.tech_name,m.tech_price,m.tech_type,c.creation_time,c.check_state from check_request c,medical_technology m where c.register_id=#{registerId} and c.medical_technology_id=m.id")
    public List<CheckCharge> getCheckFee(int registerId);

    //缴费
    @Update("update check_request set check_state=#{drugState} where id=#{id}")
    public int charge(String drugState,int id);

    //开设检查时：点击确认后在对应表中插入挂号id、医技id、开立时间、状态
    @Insert("INSERT INTO check_request (register_id, medical_technology_id,creation_time,check_state) VALUES (#{registerId}, #{medicalTechnologyId},#{creationTime},#{checkState})")
    public int insert(int registerId, int medicalTechnologyId, LocalDateTime creationTime, String checkState);

    //得到刚刚插入的id
    @Select("SELECT LAST_INSERT_ID()")
    public int getInsertId();

    //在得到id的基础上添加其他数据
    public int updateOthers(int id,String checkInfo,String checkPosition,String checkRemark);

    //根据挂号id查询检查结果
    @Select("SELECT * FROM check_request where register_id=#{registerId}")
    public List<CheckRequest> getCheck(int registerId);

    //根据检查id查询
    @Select("select * from check_request where id=#{id}")
    public CheckRequest selectById(int id);

    //根据id删除
    @Delete("delete from check_request where id=#{id}")
    public int deleteById(int id);

    //搜索挂号id对应的检查结果信息
    @Select("select m.tech_name,c.check_position,c.check_info,c.check_result,c.check_time,c.check_state from medical_technology m,check_request c where c.medical_technology_id=m.id and register_id=#{registerId}")
    public List<CheckResult> getCheckByRegisterId(int registerId);
}
